import request from "../utils/request";

export interface LoginResponse {
  code: number;
  msg: string;
  data: {
    user: {
      id: number;
      username: string;
      password: string; // 这通常不应返回
      role: string;
    };
    token: string;
  };
}
interface RegisterResponse {
  code: number;
  msg: string;
  data?: any; // 可选的返回数据
}

export const loginUser = async (username: string, password: string): Promise<LoginResponse> => {
  return await request({
    url: "/api/login",
    method: "post",
    data: { username, password }
  }); // 返回整个响应
};

export const registerUser = async (username: string, password: string): Promise<RegisterResponse> => {
  return await request({
    url: "/api/register",
    method: "post",
    data: { username, password }
  });
};
